#include <iostream>

using namespace std;

const int N = int (1e5 + 10);
const int M = int (1e6 + 10);

int Next[N];

int p[N], s[M];
int n, m;

void Get_Next(void)
{
    Next[0] = -1;
    int j = 0, k = -1;
    while (j < n) // j 需要去到最后一个字符处, 并且Next数组的大小是 N + 1
    {
        if (k == -1 || p[j] == p[k])
        {
            k++; j++;
            Next[j] = k; // 可以优化这里吗?应该不太行
        }
        else k = Next[k];
    }
}

void Find_index(void)
{
    Get_Next();
    int i = 0, j = 0;
    while (i != m)
    {
        if (j == n)
        {
            printf("%d ", i - j);
            j = Next[j];
        }
        else if (j == -1 || s[i] == p[j])
        {
            j++, i++;
        }
        else j = Next[j];
    }
    if (j == n) printf("%d ", i - j);
}

int main(void)
{
    scanf("%d", &n); cin.get();
    for (int i = 0; i < n; i++) scanf("%c", &p[i]);
    scanf("%d", &m); cin.get();
    for (int i = 0; i < m; i++) scanf("%c", &s[i]);
    
    Find_index();
}